package com.ruoyi.common.utils.sms;


import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyun.teaopenapi.models.Config;

public class SmsUtils {
    public static final String accessKeyId = "LTAInyz6yZxB5vli";
    public static final String accessKeySecret = "CksCKoWc4LgszOjOzXZr8ay08yQWxt";
    public static final String signName = "智能销售系统";

//    public static final String accessKeyId = "LTAI4GDFq2KpsUH97wNXPwVB";
//    public static final String accessKeySecret = "MJflJEeho1Vu3rngsP39D3tjNkaxJ4";
//    public static final String signName = "潍坊数云创想";

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */

    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }
    public static void sendSmsReg(String mobile,String code) throws Exception {
        Client client = createClient(accessKeyId,accessKeySecret);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(mobile)
                .setSignName(signName)
                .setTemplateCode("SMS_144735188")
        .setTemplateParam("{ \"code\":\""+code+"\"}");
        client.sendSms(sendSmsRequest);
    }

    /**
     * 账号绑定
     * @param mobile
     * @param code
     * @throws Exception
     */
    public static void sendSmsBind(String mobile,String code) throws Exception {
        Client client = createClient(accessKeyId,accessKeySecret);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(mobile)
                .setSignName(signName)
//                .setTemplateCode("SMS_218159217")
                .setTemplateCode("SMS_152514263")
                .setTemplateParam("{ \"code\":\""+code+"\"}");
        client.sendSms(sendSmsRequest);
    }

    public static void sendSms(String mobile,String code,String temCode) throws Exception {
        Client client = createClient(accessKeyId,accessKeySecret);
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(mobile)
                .setSignName(signName)
                .setTemplateCode(temCode)
                .setTemplateParam("{ \"code\":\""+code+"\"}");
        client.sendSms(sendSmsRequest);
    }
    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.dysmsapi20170525.Client client = SmsUtils.createClient("LTAI4GDFq2KpsUH97wNXPwVB", "MJflJEeho1Vu3rngsP39D3tjNkaxJ4");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers("15318901810")
                .setSignName("潍坊数云创想")
                .setTemplateCode("SMS_192335626")
                .setTemplateParam("{\"code\":\"1230\"}");
        // 复制代码运行请自行打印 API 的返回值
        System.out.println(client.sendSms(sendSmsRequest));
    }
}
